package com.black.web.controller.system;

import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.black.system.domain.req.system.query.SysDeptQueryReq;
import com.black.system.domain.req.system.query.SysUserQueryReq;
import com.black.system.domain.resp.system.SysDeptTreeResp;
import com.black.system.domain.resp.system.SysUserResp;
import com.black.system.service.SysDeptService;
import com.black.system.service.SysUserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "后台-用户管理Api")
@RestController
@RequestMapping("/admin/user")
public class SysUserController extends BaseController {

    /**
     * 部门业务逻辑
     */
    @Autowired
    private SysDeptService sysDeptService;
    /**
     * 用户业务逻辑
     */
    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "获取部门树")
    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping(value = "/deptTree")
    public R<List<SysDeptTreeResp>> deptTree() {
        List<SysDeptTreeResp> treeResp = this.sysDeptService.allDeptTree(new SysDeptQueryReq());
        return R.ok(treeResp);
    }

    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @ApiOperation(value = "分页查询")
    @GetMapping(value = "/list")
    public R<PageInfo<SysUserResp>> list(SysUserQueryReq req) {
        PageInfo<SysUserResp> page = this.sysUserService.paginationQuery(req);
        return R.ok(page);
    }

}
